<template>
	<view class="page">
		<view class="top">
			<view class="success">
				<image src="../../static/image/blue-dui.png"></image>
				报价单生成成功
			</view>
			<view class="top-tips">此结果仅供参考，实际费用以当地为准</view>
		</view>
		<view class="content">
			<view class="car-name">
				<view class="name">{{bannerInfo.style_name}}</view>
				<view class="car-class">
					<view class="model">{{bannerInfo.model_name}}</view>
					<view class="car-btn" @click="changeModel">更换车型</view>
				</view>
			</view>
			<view class="money-box">
				<view class="tab-top">
					<view class="tab">
						<view @click="changeTab(1)" :class="isActive == 1 ? 'item active': 'item'">全款</view>
						<view @click="changeTab(2)" :class="isActive == 2 ? 'item active': 'item'">分期</view>
					</view>
					<view class="city">购车城市：{{cityName}}</view>
				</view>
				<view class="list">
					<view class="li" v-for="(item,index) in moneyList" :key="item.title">
						<view class="title-li">
							<view class="title">{{item.title}}</view>
							<view :class="item.isSmall ? 'small': 'money'">{{item.price}}<view class="unit">{{item.price_unit}}</view></view>
						</view>
						<view class="grey" v-if="item.desc">
							<view style="margin-top: -20rpx;">{{item.desc}}</view>
						</view>
						<view class="grey" v-for="val in item.details" :key="val.name">
							<view>{{val.name}}</view>
							<view>{{val.val}}</view>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		<uni-popup ref="popup"  mask-background-color="rgba(0,0,0,.4)" safe-area="true">
			<view class="car-box">
				<view class="cancel-title">
					<view class="cancel" @click="closeModal">取消</view>
					<view class="title">选择意向车型</view>
				</view>
				<view class="model-list">
					<view class="li" v-for="item in modelList" :key="item.model_hid" @click="changeCar(item)">
						{{item.model_name}}
						<uni-icons v-show="item.isSelected == 1" class="icon" type="checkmarkempty" size="20"></uni-icons>
					</view>
				</view>
			</view>	
		</uni-popup>
		<view v-if="bannerInfo.act_is_show">
			<view class="mask" v-show="isGuang">
				<view class="guang-box">
					<view class="image-box">
						<image style="height: 804rpx;" mode="heightFix"  class="guang-tu" :src="bannerInfo.act_banner"></image>
						<button plain="true" class="guang-btn" open-type="openAwemeUserProfile" @openawemeuserprofile="eventHandler" :data-aweme-id="infoData.douyin_num">立即私信主播领取</button>
					</view>
					<image @click="closeGuang" class="cha" src="../../static/image/cha.png" mode=""></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	const Api = require('../../utils/api.js');
	const request = require('../../utils/request.js');
	
	export default {
		data(){
			return {
				moneyList: [],
				isActive: 1,
				modelList: [],
				model_hid: '',
				city_id: '',
				style_hid: '',
				cityName: '',
				bannerInfo: {},
				infoData: {},
				isGuang: true,
			}
		},
		onLoad(options){
			console.log(options, "报价单成功")
			this.city_id = options.city_id
			this.style_hid = options.style_hid
			this.cityName = options.city_name
			
			this.infoData = options
			this.getCarInfo()
			
			this.getModalList()
		},
		methods: {
			//获取车辆信息
			getCarInfo() {
				request.http({
					url:Api.leave_success,
					header: {
						// 'content-type': 'application/x-www-form-urlencoded',
					},
					type: 'GET',
					data: {
						style_hid:  this.style_hid,
						city_id:  this.city_id,
						special_hid: this.infoData.special_hid,
						nickname: this.infoData.douyin_name,
						phone: this.infoData.phone,
						is_send_sms: this.infoData.is_send_sms,
						kol_id: this.infoData.kol_id
					},
					 
				}).then(res => {
					// console.log(res, '333')
					console.log(res.data, 'che')
					this.bannerInfo = res.data
					this.getMoneyList()
				})
			},
			// 获取价格
			getMoneyList() {
				request.http({
					url:Api.quotation_success,
					header: {
						// 'content-type': 'application/x-www-form-urlencoded',
					},
					type: 'GET',
					data: {
						city_id:  this.city_id,
						cate: this.isActive,
						model_hid: this.bannerInfo.model_hid
					},
					 
				}).then(res => {
					// console.log(res, '333')
					console.log(res.data, '价格')
					if(this.isActive == 1) {
						res.data.list.map((item,index) => {
							if(index >= 2) {
								item.isSmall = true
							}
						})
					} else { 
						res.data.list.map((item,index) => {
							if(index >= 3) {
								item.isSmall = true
							}
						})
					}
					this.moneyList = res.data.list
					
				})
			},
			 changeTab(val) {
				 this.isActive = val
				 this.getMoneyList()
			 },
			 getModalList(){
				 request.http({
				 	url:Api.car_model_list,
				 	header: {
				 		// 'content-type': 'application/x-www-form-urlencoded',
				 	},
				 	type: 'GET',
				 	data: {
				 		style_hid: this.style_hid,
						city_id:  this.city_id,
				 	},
				 	 
				 }).then(res => {
				 	// console.log(res, '333')
				 	console.log(res.data, '价格')
					res.data.list.map(item => {
						item.isSelected = 0
					})
				 	this.modelList = res.data.list
				 	
				 })
			 },
			 changeModel() {
				 this.$refs.popup.open('bottom')
			 },
			 closeModal(){
				  this.$refs.popup.close()
			 },
			 changeCar(item) {
				this.$refs.popup.close()
				this.isActive = 1
				this.bannerInfo = item
				this.getMoneyList()
				this.modelList.map(val => {
					if(val.model_hid == item.model_hid){
						val.isSelected = 1
					} else {
						val.isSelected = 0
					}
				})
			 },
			 
			 closeGuang() {
			 	this.isGuang = false
			 },
			 eventHandler(e) {
			     if (e.detail.errNo) {
			 	  console.log("跳转抖音号个人页失败", e.detail);
			 	} else {
			 	  console.log("跳转抖音号个人页成功");
			 	}
			 },
		}
	}
</script>

<style lang="scss" scoped>
	.page{
		width: 100%;
		height: 100vh;
		background: #F6F7FC;
		.top {
			width: 100%;
			height:500rpx ;
			background-image: linear-gradient(180deg, #3082FF 0%, #0061F4 42%, #F6F7FC 100%);
			display: flex;
			flex-direction: column;
			align-items: center;
			.success {
				display: flex;
				font-weight: 500;
				font-size: 40rpx;
				color: #FFFFFF;
				margin-top: 64rpx;
				image {
					width: 48rpx;
					height: 48rpx;
					margin-right: 16rpx;
				}
			}
			.top-tips{ 
				font-size: 28rpx;
				color: #FFFFFF;
				letter-spacing: 1rpx;
				margin-top: 24rpx;
			}
		}
		
		.content {
			width: 100%;
			margin-top: -270rpx;
			padding: 0 32rpx;
			box-sizing: border-box;
			margin-bottom: 100rpx;
			.car-name {
				width: 100%;
				display: flex;
				flex-direction: column;
				padding: 32rpx 32rpx 45rpx 32rpx;
				box-sizing: border-box;
				background: #fff;
				opacity: 0.7;
				border-radius: 16rpx 16rpx 0 0;
				.name {
					font-weight: 500;
					font-size: 34rpx;
					color: #222526;
					margin-bottom: 24rpx;
				}
				.car-class {
					width: 100%;
					display: flex;
					justify-content: space-between;
					.model {
						font-weight: 400;
						font-size: 28rpx;
						color: #222526;
					}
					.car-btn {
						font-weight: 500;
						font-size: 28rpx;
						color: #3075FE;
					}
				}
			}
			
			.money-box {
				width: 100%;
				background: #fff;
				border-radius: 16rpx;
				padding: 28rpx 32rpx ;
				box-sizing: border-box;
				margin-top: -10rpx;
				.tab-top {
					width: 100%;
					display: flex;
					justify-content: space-between;
					align-items: center;
					.tab {
						display: flex;
						.item{
							font-size: 32rpx;
							color: #6E7175;
							margin-right: 40rpx;
						}
						.active {
							color: #222526;
							font-weight: 600;
							font-size: 36rpx;
							margin-top: -5rpx;
							position: relative;
							&::before {
								content: "";
								position: absolute;
								bottom: -10rpx;
								left: 50%;
								transform: translate(-50%, 0);
								width: 29rpx;
								height:6rpx ;
								background-image: url(../../static/image/active.png);
								background-size: 100% 100%;
							}
						}
					}
					
					.city {
						font-size: 24rpx;
						color: #6E7175;
						text-align: center;
					}
				}
				
				.list {
					width: 100%;
					margin-top: 40rpx;
					.li:last-child{
						border-bottom: none;
					}
					.li{
						width: 100%;
						// height: 118rpx;
						padding: 32rpx 0 ;
						box-sizing: border-box;
						border-bottom: 1rpx dashed #DCDDE0;;
						display:flex;
						flex-direction: column;
						.title-li, .grey {
							display: flex;
							justify-content: space-between;
						}
						.title-li {
							.title {
								font-weight: 500;
								font-size: 32rpx;
								color: #222526;
							}
							.money {
								font-weight: 600;
								font-size: 36rpx;
								color: #222526;
								display: flex;
								align-items: center;
								.unit {
									font-weight: 600;
									font-size: 24rpx;
									color: #222526;
									margin-left: 5rpx;
								}
							}
							.small {
								font-weight: 600;
								font-size: 28rpx;
								color: #222526;
								display: flex;
								align-items: center;
								.unit {
									font-weight: 600;
									font-size: 24rpx;
									color: #222526;
									margin-left: 5rpx;
								}
							}
						}
						
						.grey {
							margin-top: 28rpx;
							view {
								font-weight: 400;
								font-size: 24rpx;
								color: #6E7175;
							}
						}
					}
				}
			}
		}
		
		.car-box {
			width: 100%;
			height: 1000rpx;
			padding: 0 32rpx;
			box-sizing: border-box;
			background: #fff;
			display: flex;
			flex-direction: column;
			.cancel-title {
				width: 100%;
				display: flex;
				
				align-items: center;
				padding: 29rpx 0;
				box-sizing: border-box;
				border-bottom: 1rpx solid #DCDDE0;
				
				.cancel {
					font-weight: 400;
					font-size: 32rpx;
					color: #222526;
				}
				.title {
					// flex: 1;
					margin-left: 200rpx;
					text-align: center;
					font-weight: 500;
					font-size: 36rpx;
					color: #222526;
				}
			}
			.model-list {
				width: 100%;
				overflow-y: auto;
				.li {
					width: 100%;
					height: 110rpx ;
					line-height: 110rpx;
					font-weight: 500;
					font-size: 32rpx;
					color: #222526;
					border-bottom: 1rpx solid #DCDDE0;
					display: flex;
					justify-content: space-between;
				}
			}
		}
		
		.mask {
			width: 100%;
			height: 100vh;
			background: rgba(0, 0, 0, .4);
			
			position: fixed;
			top:0;
			left: 0;
			.guang-box {
				
				position: absolute;
				top: 58%;
				left: 50%;
				transform: translate(-50%, -58%);
				display: flex;
				flex-direction: column;
				align-items: center;
				justify-content: center;
				.image-box{
					margin-top:-160rpx;
					position: relative;
					.guang-btn {
						position: absolute;
						bottom: 84rpx;
						left:50%;
						transform: translateX(-50%);
						width: 440rpx;
						height: 80rpx;
						background-image: linear-gradient(90deg, #8D5433 0%, #5D2602 100%);
						border-radius: 40rpx;
						font-size: 30rpx;
						color: #FFFFFF;
						line-height: 80rpx;
					
					}
				}
				.cha {
					width: 64rpx;
					height: 64rpx;
					margin-top: 20rpx;
				}
			}
		}
	}
</style>  

<style>	
	button::after {
	      border: none;
	}
</style>